<?php
include_once('common/header.php');			
if($AppUI->id <=0 || !isset($_SERVER['HTTP_REFERER'])) {
	Vfriend_Function::redirect(HOST_VFRIEND);
}
$arrParam		= $objRequest->getParams();
$intOfflineId	= isset($arrParam['offlineid']) ? $arrParam['offlineid'] : 0;
$strToken		= isset($arrParam['token']) ? $arrParam['token'] : '';
$arrUserId		= isset($arrParam['puserid']) ? $arrParam['puserid'] : null;
$strSession		= Vfriend_Function::getSecret($intOfflineId, SE_OFFLINE_INVITE);
$strRefer		= isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
$intError		= 0;
if(Vfriend_Function::isValidLink($strRefer) && $strToken != '' && $strToken == $strSession && isset($arrUserId) && $arrUserId) {
	Vfriend_Function::deleteSecret($intOfflineId, SE_OFFLINE_INVITE);
	$objOffline = new Offline();
	$intCuser	= count($arrUserId);
	$intCerr	= 0;
	$intIerr	= 0;
	foreach($arrUserId as $value) {
		if($value != "") {
			$intIerr	= $objOffline->ojoinReg($value, $intOfflineId, $AppUI->id, -1);
			if($intIerr > 0) {			
				$intCerr ++;
			}
		} else {
			$intCuser --;
		}
	}
	if($intCerr == $intCuser) {
		$intError = 24;
	} else {
		$intError = 0;
		Vfriend_Function::setMsg($arrMessage[8]);
	}
} else {
	$intError	= 18;
}
if($intError > 0) {	
	Vfriend_Function::setError($arrError[$intError]);	
}
$strRefer	= $strRefer ? $strRefer : LINK_OFFLINE;
Vfriend_Function::redirect($strRefer);
?>